package logic

import (
	"context"
	"grpc.getaway.adminspro.padmins.com/internal/rpc/utils/database"
	"grpc.getaway.adminspro.padmins.com/pkg/config/businessError"
)

func GetRoles(ctx context.Context, id int64) (map[int64]string, *businessError.ErrorInfo) {
	rows, e := database.Db.GetDefaultDb(ctx).Query("select ag.name,ag.id from admin_role_access aga join admin_role ag on aga.role_id=ag.id where aga.admin_id=?", id)

	if e != nil {
		return nil, businessError.DbError(e)
	}

	data := map[int64]string{}
	for _, row := range rows {
		data[row["id"].(int64)] = row["name"].(string)
	}
	return data, nil
}
